package com.sw.chinesewriteboard.config;

import android.content.Context;

public class ChineseDataConfig {

    public static final int A4WIDTH = 210; // 210mm
    public static final int A4HEIGHT = 297; // 297mm

    public static int TOTAL_LENGTH_COLUMN = 12; // 总共字长，11个字
    public static int TOTAL_LENGTH_ROW = 16; // 行，8行
    public static int TOTAL_LENGTH = TOTAL_LENGTH_COLUMN * TOTAL_LENGTH_ROW;  // 总字数
    public static int GRID_WIDTH = 15;  // 格子宽度 单位（mm// 厘米）

    public static int getGridWidth(Context context) {
        return (int) (GRID_WIDTH * context.getResources().getDisplayMetrics().xdpi * (1.0f / 25.4));
    }

    public static void setGridWidth(int gridWidth, boolean hasPinyin) {
        ChineseDataConfig.GRID_WIDTH = gridWidth;
        if (gridWidth == 13) {
            TOTAL_LENGTH_COLUMN = 14;
            TOTAL_LENGTH_ROW = hasPinyin ? 12 : 17;
            TOTAL_LENGTH = TOTAL_LENGTH_COLUMN * TOTAL_LENGTH_ROW;
        }

        if (gridWidth == 15) {
            TOTAL_LENGTH_COLUMN = 12; // 总共字长，11个字
            TOTAL_LENGTH_ROW = hasPinyin ? 10 : 16; // 行，8行
            TOTAL_LENGTH = TOTAL_LENGTH_COLUMN * TOTAL_LENGTH_ROW;  // 总字数
        }

        if (gridWidth == 17) {
            TOTAL_LENGTH_COLUMN = 10;
            TOTAL_LENGTH_ROW = hasPinyin ? 9 : 14;
            TOTAL_LENGTH = TOTAL_LENGTH_COLUMN * TOTAL_LENGTH_ROW;
        }

    }

    public static void setRow(int row) {
        TOTAL_LENGTH_ROW = row; // 行，8行
        TOTAL_LENGTH = TOTAL_LENGTH_COLUMN * TOTAL_LENGTH_ROW;  // 总字数
    }

    public static int getA4width(Context context) {
        return (int) (A4WIDTH * context.getResources().getDisplayMetrics().densityDpi * (1.0f / 25.4));
    }

    public static int getA4height(Context context) {
        return (int) (A4HEIGHT * context.getResources().getDisplayMetrics().densityDpi * (1.0f / 25.4));
    }

    public static int mm2px(Context context, int length) {
        return (int) (length * context.getResources().getDisplayMetrics().xdpi * (1.0f / 25.4));
    }
}
